package com.panda.controller.video;

import com.panda.annotation.PageView;
import com.panda.annotation.SystemLog;
import com.panda.constants.SystemConstants;
import com.panda.entity.vo.CommentVo;
import com.panda.entity.vo.VideoVo;
import com.panda.service.CommentService;
import com.panda.service.VideoService;
import com.panda.utils.RespondResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/videos")
@Api(tags = "视频接口")
public class VideoController {

    @Autowired
    private VideoService videoService;
    @Autowired
    private CommentService commentService;

    @GetMapping
    public RespondResult getAllVideos(@NotNull(message = "页码不能为空") Integer pageNum, @NotNull(message = "每页大小不能为空") Integer pageSize, Long categoryId, String keyword) {
        return videoService.getAllVideos(null, pageNum, pageSize, categoryId,keyword);
    }

    @GetMapping("/{id}")
    public RespondResult getVideoDetail(@PathVariable Long id) {
        return videoService.getVideoDetail(id);
    }

    @DeleteMapping("/{id}")
    public RespondResult deleteVideo(@PathVariable Long id) {
        return videoService.deleteVideo(id);
    }

    @ApiOperation("上传视频")
    @PostMapping
    public RespondResult postVideo(@Validated @RequestBody VideoVo videoVo) {
        return videoService.postVideo(videoVo);
    }

    @ApiOperation("修改视频")
    @PutMapping("/{id}")
    public RespondResult modifyVideo(@PathVariable Long id ,@Validated @RequestBody VideoVo videoVo) {
        return videoService.modifyVideo(id,videoVo);
    }

    @ApiOperation("视频评论")
    @GetMapping("/{id}/comments")
    public RespondResult getComment(@PathVariable Long id, Integer pageNum, Integer pageSize) {
        return commentService.getComment(SystemConstants.VIDEO_COMMENT_TYPE, id, pageNum, pageSize);
    }

    @ApiOperation("发表评论")
    @PostMapping("/{id}/comments")
    public RespondResult postComment(@PathVariable("id") Long id, @RequestBody CommentVo commentVo) {
        return commentService.postComment(SystemConstants.VIDEO_COMMENT_TYPE, id, commentVo);
    }
    @ApiOperation("发表评论")
    @GetMapping("/hot")
    public RespondResult hotVideos(@RequestParam String topic){
        return videoService.hotVideos(topic);
    }
}
